/*
 * @Author: your name
 * @Date: 2023-10-11 13:03:45
 * @LastEditTime: 2023-10-23 10:13:44
 * @LastEditors: Please set LastEditors
 * @Descripttion: In User Settings Edit
 * @FilePath: /bicycle-mobile-old/h5/src/pages/likeNewsList/index.jsx
 */
import React, { useEffect } from 'react'
import styles from './index.less'
import InViewPort from '../../components/InViewPort'
import NewsCard from '../../components/newsCard'
import { useDispatch, useSelector } from 'dva'
import ReturnIndex from "../../components/returnIndex"

function Index() {
  const dispatch = useDispatch()
  const {
    likeNewsList,
    userInfo
  } = useSelector(({ index }) => index)

  useEffect(() => {
    dispatch({
      type: 'index/apiGetLikeNewsList',
      payload: {
        objectType: 'ARTICLE',
        type:'COLLECTED',
        userId:  userInfo?.user?.id
      }
    })
  }, [])

  function onEnter() {
    // console.log("onEnter")
  }
  return (
    <div className={styles.page}>
       <ReturnIndex/>
      <div className={styles.myBody}>
        {
          likeNewsList && likeNewsList.map((item, index) => {
            if (index == (likeNewsList.length - 1)) {
              return <InViewPort key={index} onEnter={onEnter}>
                <NewsCard
                  obj={item.object}
                  type={2}
                ></NewsCard>
              </InViewPort>
            }
            return <NewsCard
              key={index}
              type={2}
              obj={item.object}
            ></NewsCard>
          })
        }
      </div>
    </div>
  )
}

export default Index
